<template>
  <div>
    <!--<x-header :title=this_page_title style="position:fixed;top:0px;z-index:1000;width:100%" :right-options="{showMore: true}" @on-click-more="show = true"></x-header> -->

    <x-header>
      <span>{{this_page_title}}</span>
      <x-icon @click="goBackBtn" slot="ios-arrow-left" type="ios-arrow-back" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
      <x-icon @click="hengshuBtn" v-if="isHeng" slot="right" type="android-menu" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
      <x-icon @click="hengshuBtn" v-if="!isHeng" slot="right" type="android-apps" size="35" style="fill:#fff;position:relative;top:-8px;left:-3px;"></x-icon>
    </x-header>

    <!-- <shop-cell :list="list"></shop-cell> -->
    <!--<shoplist-page :shoplistData="shoplistData" style="margin-top:50px"></shoplist-page>-->
    
    
    <shop-list v-show="isHeng" :shopList="shoplistData"></shop-list>
    <shoplist-page v-show="!isHeng" :shoplistData="shoplistData"></shoplist-page>
        
  
  
  </div>
  <!--<div v-show="changesIcon==true" class="Search_cancel search-cancel f-l" @click="hengshuBtn"><img src="/static/bottom/paiheng.png" alt=""></div>
  <div v-show="changesIcon==false" class="Search_cancel search-cancel f-l" @click="hengshuBtn"><img src="/static/bottom/fenleidi@2x.png" alt=""></div>-->
              
</template>



<style>
</style>

<script>
import { XHeader } from 'vux'
import shopList from '../../components/toolComponent/shopList.vue'
import shoplistPage from '../../components/toolComponent/shoplistPage.vue'
import $ from 'jquery';
import { homeUrl } from "../../components/utils/utils.js";
import axios from "axios";
import qs from "qs";
export default {
  components: {
    XHeader,
    shoplistPage,
    shopList
  } , 
    data () {
    return {
      isHeng:false , 
      this_page_title:"浏览记录" , 
      shoplistData:[],
      wxOpenId:localStorage.getItem("openid"),
      fromPosition:localStorage.getItem("fromPosition") , 
      dataUrl:"favoriteAndLookTableManageJsonSelect/"
    }
  },
  mounted: function () {
    if (this.$data.fromPosition == "jifen") {
      this.$data.dataUrl = "jifenListJson/"
      this.$data.this_page_title = "积分商城"
      
    }
    this.historyData();
    
    this.$nextTick(function () {
      // 视频滚动区域高度
      var windowHeight = $(window).height()
      var headerHeight = $(".vux-header").outerHeight()
      $("#mylist").height(windowHeight - headerHeight)
    })
    
  },
  methods:{
    goBackBtn() {
      window.history.go(-1)
    } , 
    hengshuBtn() {
      this.$data.isHeng = !this.$data.isHeng
    } , 
    historyData(){
      var that = this
      var datas = qs.stringify({
        wxid:this.wxOpenId,
        tablename:"lookhistory"
      });
      axios
        .post(homeUrl() + this.$data.dataUrl, datas, { emulateJSON: true })
        .then(
          result => {
            
            var searchArr=[];
            var datasList = result.data.data;
          
            for(var i=0;i<datasList.length;i++){
              var oneGoods = ""
              if (datasList[i].goods == undefined) {
                oneGoods = datasList[i]
              } else {
                 oneGoods = datasList[i].goods
              }
              var searchObj = {};
              searchObj.src =this.urlList(oneGoods.product_thumb_image);
                // ;
              searchObj.title = oneGoods.goodsname;
              searchObj.desc=oneGoods.standard
              
              searchObj.goodsid = oneGoods.goodsid;
              searchObj.shop_price=oneGoods.shop_price;
              searchObj.market_price=oneGoods.market_price;
              if (localStorage.getItem("fromPosition") == "jifen") {
                searchObj.shop_price=oneGoods.jifenprice;
                searchObj.market_price=oneGoods.shop_price;
              }
              
              searchObj.rebate="返利￥"+oneGoods.rebate+"元";
              searchObj.kucun=oneGoods.counts;
              searchObj.sellCount=oneGoods.sellcount;
              
              searchArr.push(searchObj);

            }
            this.shoplistData = searchArr;
            localStorage.removeItem("fromPosition")
          },
          error => {
            localStorage.removeItem("fromPosition")
            this.$vux.toast.text("网络请求失败....", "bottom");
            console.log(error);
          }
        );
    },
       // 图片
        urlList(imgObj){
        if(imgObj!=null){
            //  var datasSrc=imgObj.split("---");
            var srcUrl=homeUrl()+imgObj;
            return srcUrl
        }
        },
    
  },
  created(){
    // this.historyData()
  }
}
</script>